home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSSTR1.C < prev    next >
C/C++ Source or Header  |  1993-09-02  |  3KB  |  97 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bsstr.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains utility string functions. This modules uses floating 
  25. //    point so it is in a separate module.
  26. //
  27. //    The code in this module should be written entirely in C. 
  28. //    Do not use any C++ constructs.
  29. //
  30. //    This module is portable to:
  31. //        DOS 3.X+
  32. //        MS Windows 3.X+
  33. //        OS/2 2.X+
  34. //        OS/2 2.0 PM
  35. //        SCO UNIX.
  36. //
  37. //    The following compilers are supported:
  38. //        MSC 6.0A
  39. //        MSC/C++ 7.0
  40. //        Borland C++ 3.1 for DOS
  41. //        Borland C++ 1.0 for OS/2 2.X
  42. //        SCO UNIX cc
  43. //
  44. //----------------------------------------------------------------------------
  45. #include <bs.h>
  46.  
  47.  
  48. //----------------------------------------------------------------------------
  49. //   Description:    Extract double value from a string.
  50. //    Parameters:    psz            String
  51. //                        pg                Pointer to double value storage. If null, don't
  52. //                                        save value. Contains 0.0 if return is FALSE.
  53. //       Returns:    TRUE if string represented a valid long.
  54. //----------------------------------------------------------------------------
  55. BOOL FN_E strvaliddouble(PSZ psz, PDOUBLE    pg)
  56. {
  57.     PSZ pszSave = psz;
  58.  
  59.  
  60.     Assert(psz);
  61.     psz = strskipws(psz);                    // Skip leading whitespace 
  62.     if (psz[0] == '+' || psz[0] == '-') 
  63.         psz++;                                    // Skip sign 
  64.  
  65.     while (isdigit(psz[0]))                    // Skip integral digits 
  66.         psz++;
  67.  
  68.     if (psz[0] == '.')
  69.         {
  70.         psz++;
  71.         while (isdigit(psz[0]))                // Skip decimal digits 
  72.             psz++;
  73.         }
  74.     if (psz[0] == 'd' || psz[0] == 'D' || psz[0] == 'e' || psz[0] == 'E')
  75.         {
  76.         psz++;                                    // Skip exponent 
  77.         if (psz[0] == '+' || psz[0] == '-') 
  78.             psz++;                                // Skip sign 
  79.         while (isdigit(psz[0]))                // Skip digits 
  80.             psz++;
  81.         }
  82.     psz = strskipws(psz);                    // Skip trailing whitespace 
  83.     if (psz[0])                                    // Anything but a null means failure 
  84.         {
  85.         if (pg)
  86.             pg[0] = 0.0;
  87.         return FALSE;            
  88.         }
  89.     if (pg)
  90.         pg[0] = atof(pszSave);
  91.     return TRUE;
  92. }
  93. //----------------------------------------------------------------------------
  94. //------------------------------- End of File --------------------------------
  95. //----------------------------------------------------------------------------
  96.  
  97.